package testSudoku;

/*integration_test on classes
  (Manager,Validator,QuestionFactory,Sudoku Question and Board,easy_qustion,medium_qustion and hard_qustion)
 */
import static org.junit.Assert.*;

import org.junit.Test;
import sudoku.*;
import junit.framework.TestCase;
public class integration_test2 {
	
	//Test1 : Test whether manger can copy the question to Board (Difficult : Easy)
	@Test
	public void testEasyQuestion()
	{
		Manager m = new Manager(1,0);
		Board bd = m.getboard();
		easy_qustion q = new easy_qustion();
		char [][]result = q.get_question(0);	
		assertArrayEquals(result,bd.getboard());
	}
	
	//Test2 : Test whether manger can copy the question to Board (Difficult : Medium)
	@Test
	public void testMediumQuestion()
	{
		Manager m = new Manager(2,0);
		Board bd = m.getboard();
		medium_qustion q = new medium_qustion();
		char [][]result = q.get_question(0);	
		assertArrayEquals(result,bd.getboard());
	}
	
	//Test3 : Test whether manger can copy the question to Board (Difficult : Hard)
	@Test
	public void testHardQuestion()
	{
		Manager m = new Manager(3,0);
		Board bd = m.getboard();
		hard_qustion q = new hard_qustion();
		char [][]result = q.get_question(0);	
		assertArrayEquals(result,bd.getboard());
	}

	//Test 4: when surrender , will board contain solution or not
	@Test
	public void testSurrender()
	{
		Manager m = new Manager(1,0);
		m.surrender();
		Board bd = m.getboard();
		easy_qustion q = new easy_qustion();
		char [][]result = q.get_solution(0);
		assertArrayEquals(result,bd.getboard());
	}
	
	//Test 5: Test setBoard function
	@Test
	public void testSetBoard()
	{
		Manager m = new Manager(3,2);
		m.set_board(0,0,'6');
		char result = '6';
		Board bd = m.getboard();
		char [][] Array = bd.getboard();

		assertEquals(result,Array[0][0]);
	}
	
	//Test 6: Test count steps
	@Test
	public void testcount_step()
	{ 
		Manager m = new Manager(3,1);
		m.set_board(0,0,'1');
		m.set_board(1,0,'2');
		m.set_board(2,0,'3');
		m.set_board(3,0,'4');
		int result = 4 ;
		assertEquals(result,m.count_step(3));
		
	}
	
	//Test 7: Wrong x position input should not record on Board
	@Test
	public void testValidof_X()
	{
		Manager m = new Manager(3,0);
		Validator v = new Validator();
		hard_qustion q = new hard_qustion();
		Board bd = m.getboard();
		char [][]result = q.get_question(0);
		
		if (v.check_input(result, bd.getboard(), 100, 0,"1",'1',0))
			m.set_board(100,0,'1');	
		assertArrayEquals(result,bd.getboard());
	}
	
	//Test 8: Wrong y position input should not record on Board
	@Test
	public void testValidof_Y()
	{
		Manager m = new Manager(3,0);
		Validator v = new Validator();
		hard_qustion q = new hard_qustion();
		Board bd = m.getboard();
		char [][]result = q.get_question(0);
		
		if (v.check_input(result, bd.getboard(), 0, -5,"1",'1',0))
			m.set_board(0,-5,'1');	
		assertArrayEquals(result,bd.getboard());
	}
	
	//Test 9: Wrong value input should not record on Board
	@Test
	public void testValidof_Value()
	{
		Manager m = new Manager(3,0);
		Validator v = new Validator();
		hard_qustion q = new hard_qustion();
		Board bd = m.getboard();
		char [][]result = q.get_question(0);
		
		if (v.check_input(result, bd.getboard(), 0, 0,"0",'0',0))
			m.set_board(0,0,'0');
		
		assertArrayEquals(result,bd.getboard());
	}
	
	//Test 10: Wrong Repeat input should not record on Board ,
	@Test
	public void testValidof_Repeat()
	{
		Manager m = new Manager(3,0);
		Validator v = new Validator();
		Board bd = m.getboard();
		m.set_board(0,0,'8');
		hard_qustion q = new hard_qustion();
		char [][]result = {
		{'8',' ',' ','2','9','1',' ',' ',' '},
		{'4',' ',' ','5',' ','3',' ',' ','7'},
		{' ',' ','3',' ',' ',' ','8',' ',' '},
		{'7',' ','4',' ','2',' ','1',' ','9'},
		{' ','8',' ',' ',' ',' ',' ','5',' '},
		{'2',' ','1',' ','4',' ','6',' ','3'},
		{' ',' ','2',' ',' ',' ','3',' ',' '},
		{'3',' ',' ','9',' ','2',' ',' ','6'},
		{' ',' ',' ','4','3','6',' ',' ',' '}};
		
		if (v.check_input(q.get_question(0),bd.getboard(), 1, 0,"8",'8',0))
			m.set_board(1,0,'8');
		
		assertArrayEquals(result,bd.getboard());
	}

}
